import * as echarts from '../../ec-canvas/echarts';
var chart = null
function initChart(canvas, width, height) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var data = [];
  for (var i = 0; i < 5; i++) {
    data.push(
      Math.round(Math.random() * 20 + 5),
    )
  }
  var option = {
    tooltip: {},
    legend: {
      data: ['销量']
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 100,
      top: 100,
      containLabel: true
    },
    xAxis: {
      data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋"]
    },
    yAxis: {},
    series: [{
      name: '销量',
      type: 'bar',
      data: data
    }]
  };
  chart.setOption(option);
  return chart;
}

Page({
  data: {
    ec: {}
  },
  echartInit(e) {
    initChart(e.detail.canvas, e.detail.width, e.detail.height);
    var option = chart.getOption();
    option.series[0].data = [5, 10, 20, 10, 20]
    chart.setOption(option);
  },
  updateData: function (event) {
    var option = chart.getOption();
    var data = [];
    for (var i = 0; i < 5; i++) {
      data.push(
        Math.round(Math.random() * 20 + 5),
      )
    }
    option.series[0].data = data
    chart.setOption(option);
  }
})